package projet;

import java.lang.String;
import java.util.*;

import donnees.ressources.Process;
import donnees.ressources.Ressource;
/**
 *  This class uses a native C method to periodically collect the 
 *  number of processes and their states.
 *  It extends thread so it can run into a separate thread.
 *
 */

public class ProcessLoad extends Thread{
    /** time beetween two watches */
    private long watchPeriod;
    private Process proc;
    /**
     *  Constructs a ProcessLoad object 
     *
     *  @param watchPeriod - time beetween two watches
     */
    public ProcessLoad(long watchPeriod,Process proc){
	this.watchPeriod = watchPeriod;
	this.proc = proc;
    }

    /**
     *  Constructs a new Resource object containing the number 
     *  of processes in different states
     *
     *  @param process_sleep - number of processes in sleep state
     *  @param process_run - number of processes in run state
     *  @param process_idl - number of processes in intermediate creation state
     *  @param process_zomb - number of processes waiting for parent to pick up status
     *  @param process_stop - number of processes stopped
     */
    public void setValues(int process_sleep, int process_run, int process_idl, int process_zomb, int process_stop) {	
	/**** ici vous mettez le remplissage de vos structures ****/
	/*System.out.println("processes (sleep): "+ process_sleep +
	" , processes (run): "+process_run+
	" , processes (idl): "+process_idl+
	" , processes (zomb): "+process_zomb+
	" , processes (stop): "+process_stop);*/
	proc.setValeur(process_sleep);
    }

    /**
     *  Native method associated with the C function which collects state 
     *  information.
     */
    public native void StatProcess(int watchPeriod);
//	void StatProcess(int watchPeriod){
//  /****** temporaire ********/
//		while (true){
//			setValues(5,6,7,8,9);
//			for (int i=0;i<100000000;i++);//attente
//			
//		 } 
//  } 
    /**
     *  Launches a new cpuLoad object in a separate thread
     */
    public void run(){
	int tempo = (int)watchPeriod/1000;
	this.StatProcess(tempo);
	while(true){ } 
    } 
    
    static {
	System.loadLibrary("stat");
    }
}
